package com.sts.controller;

import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

import org.apache.log4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSON;
import com.sts.bean.Car;
import com.sts.bean.Car_run;
import com.sts.service.ICar_run;

/**
 * 机器人日志controller层
 * @author FENG
 *
 */

@Controller
public class Car_runController {

	private Logger log = Logger.getLogger(this.getClass()) ;
	
	@Resource
	private ICar_run icars;
	
	/**
	 * 查询所有的人员
	 */
	@RequestMapping(value="/selectCar_run", produces="text/html;charset=UTF-8")
	@ResponseBody
	public String selectCar_run(String page ,String limit ,String car_id ,String car_vs,String date_save_ele){
		log.debug("selectCar_run controller in");
		
		log.debug("car_name:" + date_save_ele + ",car_id:" + car_id);
		String str = "" ;
		List<Car_run> list = icars.selCar_run(car_id, date_save_ele) ;
		int length = icars.selSize(car_id, date_save_ele);
		log.debug("list:" + list);
		str = JSON.toJSONString(list);
		log.debug("length:" + length);
		
			str= "{\"code\":0,\"msg\":\"  \",\"count\":\""+length+"\",\"data\":"+str+"}";
		
		log.debug("selectCar_run controller out");
		
		return str ;
	}

	
	/**
	 * 插入car信息
	 * @param data
	 * @return
	 */
	@RequestMapping("/addCar_run")
	@ResponseBody
	public String addCar_run(String data){
		log.debug("addCar_run controller in");
		String result = "" ;
		log.debug("数据" + data);
		//将JSON对象转换为对象
		Car_run carrun = JSON.parseObject(data,Car_run.class) ;
		log.debug(carrun.toString());
		int b = icars.insertCar_run(carrun) ;
		if(b == 1){
			result = "success" ;
		}else {
			result = "false" ;
		}
		
		
		log.debug("addCar_run controller out");
		return result;
	}
	
	/**
	 * 访问userAdd页面
	 * 
	 */
	
	@RequestMapping("/car_runAdd")
	public String car_runAdd(){
		
		log.debug("car_runAdd  controller in");
		
		log.debug("car_runAdd  controller out");
		return "car_runAdd";
	}
	
	
	@RequestMapping("/car_log")
	public String car_log(){
		
		log.debug("car_log  controller in");
		
		log.debug("car_log  controller out");
		return "car_log";
	}
	
	
	
}
